//
//  RSSpecialFieldVC.m
//  RSTools
//
//  Created by thinkjoy on 2017/10/12.
//  Copyright © 2017年 杜瑞胜. All rights reserved.
//

#import "RSSpecialFieldVC.h"
#import "RSSpecialField.h"

@interface RSSpecialFieldVC ()

@property (weak, nonatomic) IBOutlet RSSpecialField *specialField;

@property (weak, nonatomic) IBOutlet UILabel *numberOfDigitsLab;
@property (weak, nonatomic) IBOutlet UIStepper *numberOfDigitsStepper;
- (IBAction)changeNumberOfDigitsStepper:(UIStepper *)sender;

@property (weak, nonatomic) IBOutlet UITextField *inputNumberStrField;
- (IBAction)ChangeInputNumberStrField:(UITextField *)sender;

@property (weak, nonatomic) IBOutlet UILabel *spaceBetweenDigitsLab;
@property (weak, nonatomic) IBOutlet UIStepper *spaceBetweenDigitsStepper;
- (IBAction)changeSpaceBetweenDigitsStepper:(UIStepper *)sender;

@property (weak, nonatomic) IBOutlet UISwitch *enableEmptyDashSwitch;
- (IBAction)clickEnableEmptyDashSwitch:(UISwitch *)sender;

@property (weak, nonatomic) IBOutlet UISwitch *secureTextEntrySwitch;
- (IBAction)clickSecureTextEntrySwitch:(UISwitch *)sender;

@end

@implementation RSSpecialFieldVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _numberOfDigitsStepper.value    =   _specialField.numberOfDigits;
    _numberOfDigitsLab.text =   [NSString stringWithFormat:@"%d",(int)_numberOfDigitsStepper.value];
    
    _inputNumberStrField.text    =   _specialField.inputNumberStr;
    
    _spaceBetweenDigitsStepper.value    =   _specialField.spaceBetweenDigits;
    _spaceBetweenDigitsLab.text =   [NSString stringWithFormat:@"%.2f",_spaceBetweenDigitsStepper.value];
    _enableEmptyDashSwitch.on   =   _specialField.enableEmptyDash;
    _secureTextEntrySwitch.on   =   _specialField.secureTextEntry;
    
    [_specialField setInputNumberHadChange:^(NSString *inputNumberStr) {
        _inputNumberStrField.text    =   inputNumberStr;
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)changeNumberOfDigitsStepper:(UIStepper *)sender {
    _specialField.numberOfDigits    =   (NSInteger)sender.value;
    _numberOfDigitsLab.text =   [NSString stringWithFormat:@"%d",(int)sender.value];
}
- (IBAction)ChangeInputNumberStrField:(UITextField *)sender {
    _specialField.inputNumberStr =   sender.text;
}
- (IBAction)changeSpaceBetweenDigitsStepper:(UIStepper *)sender
{
    _specialField.spaceBetweenDigits    =   sender.value;
    _spaceBetweenDigitsLab.text =   [NSString stringWithFormat:@"%.2f",sender.value];
}
- (IBAction)clickSecureTextEntrySwitch:(UISwitch *)sender {
    _specialField.secureTextEntry   =   sender.on;
}
- (IBAction)clickEnableEmptyDashSwitch:(UISwitch *)sender {
    _specialField.enableEmptyDash   =   sender.on;
}
@end
